package git.soulbgm.tcp.server;

import git.soulbgm.tcp.server.common.handle.TcpServerHandle;
import git.soulbgm.tcp.server.common.pojo.TcpConnectMap;
import git.soulbgm.tcp.server.common.socket.TcpServer;
import git.soulbgm.utils.ByteUtil;
import io.netty.channel.Channel;

import java.util.Collection;
import java.util.Enumeration;
import java.util.Scanner;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author SoulBGM
 * @version 1.0
 * @date 2019/11/12 15:19
 */
public class ServerApp {

    public static void main(String[] args) throws InterruptedException {
        TcpServer tcpServer = TcpServer.getTcpService(5689);
        tcpServer.start(new TcpServerHandle(tcpServer));
        Scanner input = new Scanner(System.in);
        byte[] bytes = ByteUtil.decimalToByteArray(1);
        while (input.nextLine().equals("y")) {
            ConcurrentHashMap<String, Channel> connectMap = TcpConnectMap.getConnectMap();
            Collection<Channel> values = connectMap.values();
            for (Channel channel : values) {
                tcpServer.sendMsg(channel, bytes);
            }
        }
    }

}
